<?

//Data loading
$title='LEMBAR INFORMASI PEKERJAAN (LIB)';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';
$jo_id = GetParam("jo_id","");
$TableName = "tbljoborder";


$DEFINE_FONT=0;
$pdf=new PDFReport('P',"mm","Letter");
$pdf->AddPage();
$pdf->Output();


class PDFReport extends PDF {

	function Header() {
  	  global $title,$perush,$page,$DEFINE_FONT,$ROOT_IMG_DIR, $jo_id,$DBConnection,$DBGeneral,$TableName;
            
  	  if ($DEFINE_FONT==0) {
  		 $this->AddFont('arialn','','arialn.php');
  		 $DEFINE_FONT=1;
  	  }
      
      //Fetch Data Job Order
      $SQLJO = "SELECT * FROM ".$TableName." as a
                  LEFT JOIN tbldebtur as b on a.debtur = b.CUCODE 
                  LEFT JOIN ".$DBGeneral.".tblstaff as c on a.staff_id = c.staff_id 
                  LEFT JOIN tblproject as d on a.project_id = d.project_id 
                  LEFT JOIN $DBGeneral.tblstaff as e on a.staff_id = e.staff_id
                  LEFT JOIN tblshipping_doc as f ON a.jo_id = f.jo_id
                  WHERE a.jo_id ='".$jo_id."' ORDER BY a.jo_id ASC";
      
      $ResultJO  = $DBConnection->dbc->get_results($SQLJO,ARRAY_A); 
      
      
      //Fetch Data Profile
      $SQLProf = "SELECT * FROM tblprofile 
                  WHERE prsh ='MPC' ";
      
      $ResultProf  = $DBConnection->dbc->get_results($SQLProf,ARRAY_A); 
      
      
      //Cargo Count
      $SQLCargo = "SELECT * FROM tbljocargo
                WHERE jo_id ='".$jo_id."' ORDER BY jo_id ASC";
      
      $ResultCargo  = $DBConnection->dbc->get_results($SQLCargo,ARRAY_A); 
      
      $general_cargo = 0;
	  $heavy_lift_cargo = 0;
	  $container_20 = 0;
	  $container_40 = 0;  
	  
	  $cargo_jumlah = 0; 
	  $cargo_berat = 0; 
	  $cargo_volume = 0; 
	  $cargo_lamp = 0; 
      
      if(!empty($ResultCargo))
      {
      
		  foreach($ResultCargo as $cargo_id => $cargo_val)
		  {  
			 if($cargo_val['cargo_type'] == '4')
			 {
				$general_cargo+= intval($cargo_val['cargo_jumlah']); 			
			 }
			 
			 if($cargo_val['cargo_type'] == '5')
			 {
				$heavy_lift_cargo+= intval($cargo_val['cargo_jumlah']); 
			 }
			 
			 if($cargo_val['cargo_type'] == '6')
			 {
				$container_40+= intval($cargo_val['cargo_jumlah']); 
			 }
			 
			 if($cargo_val['cargo_type'] == '7')
			 {
				$container_20+= intval($cargo_val['cargo_jumlah']); 
			 }
			 
			 
			 $cargo_jumlah+= intval($cargo_val['cargo_jumlah']); 
			 $cargo_berat+= intval($cargo_val['cargo_berat']); 
			 $cargo_volume+= intval($cargo_val['cargo_volume']); 
			 $cargo_lamp = $cargo_val['cargo_lamp']; 
			 
			 
		  }
	  
      }
      
      
      //Fetch Data Services
      $SQLSrv = "SELECT * FROM tbljoactivity as a
                 LEFT JOIN tblservices as b ON a.services_id = b.services_id
                 WHERE a.jo_id ='".$jo_id."' ORDER BY a.act_id ASC";
      
      $ResultSrv  = $DBConnection->dbc->get_results($SQLSrv,ARRAY_A);
      
      
      //Fetch Data Cargo
      $SQLCrg = "SELECT SUM(cargo_jumlah) as c_qty, SUM(cargo_berat) as c_weight, SUM(cargo_volume) as c_vol 
                 FROM tbljocargo 
                 WHERE jo_id ='".$jo_id."' GROUP BY jo_id";
      
      $ResultCrg  = $DBConnection->dbc->get_results($SQLCrg,ARRAY_A); 
      
      $fr_ton = max($ResultCrg[0]['c_qty'],$ResultCrg[0]['c_weight'],$ResultCrg[0]['c_vol']);
      
                  
      //Cargo Count
      
      
      //Get the Date Now
      $date_now = date("Y-m-d");
      list($year7,$month7,$day7) = explode("-",$date_now);
      $today  = "$day7/$month7/$year7";
      
      //Get the JO Date
      list($year1,$month1,$day1) = explode("-",$ResultJO[0]['jo_date']);
      $jo_date  = "$day1/$month1/$year1";
      
      //Get the Project Start Date
      list($year2,$month2,$day2) = explode("-",$ResultJO[0]['commencing_delivery']);
      $commencing_delivery  = "$day2/$month2/$year2";
      
      //Get the Project End Date
      list($year3,$month3,$day3) = explode("-",$ResultJO[0]['completed_delivery']);
      $completed_delivery  = "$day3/$month3/$year3";
      
      $shipment_arr = explode(".",$ResultJO[0]['jo_code']);
      $shipment = $shipment_arr[2];
      
    
             
      //End Fetch Data Job Order
           
	  $this->SetFont('arialn','',10);
	  
	  $this->Image($ROOT_IMG_DIR.'/flag_SI.jpg',12,11,34,20,'JPG');	  
	  $this->Cell(40,20,"",1,0,'C',0);
	  $this->SetFont('arialn','',18);
	  $this->Cell(150,20,"PT. MASAJI PRAYASA CARGO",1,0,'C',0);
	  
      $this->Ln();
      $this->Ln();
      
      $this->SetFont('arialn','',15);
	  $this->Cell(190,10,"DELIVERY CERTIFICATE",0,0,'C',0);
      $this->Ln();
      
      $this->SetFont('arialn','',12);
	  $this->Cell(190,6,"              We hereby certify that the undermentioned cargo have been delivered and accepted by both parties ",0,0,'L',0);
      $this->Ln();
      $this->Cell(190,6,"who undersigned this delivery certificate.",0,0,'L',0);
      $this->Ln();
      $this->Ln();
      	  
	        
      //Text Form
      $this->Cell(50,5,"Job Order No.",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['jo_code'],0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Name of Project",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['project_name'],0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Contractor",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['CUNAME'],0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Arrival",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,"",0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Departure",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,"",0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"MV / MS",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['bl_no']."  voy. ".$ResultJO[0]['vessel'],0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Issueing Delivery Order",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,"",0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Commencing Delivery",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$commencing_delivery,0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Completed Delivery",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$completed_delivery,0,0,'L',0);
      $this->Ln();
      $this->Cell(50,5,"Cargo Description",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['cargo_desc'],0,0,'L',0);
      $this->Ln();
      $this->Ln();
     
      
      
      
      $w=array(15,50,25,25,25,25,25);
                
	  $this->SetFont('arialn','',8);

	  $this->Cell($w[0],7,"NO.",1,0,'C',0);
	  $this->Cell($w[1],7,"Port Of Loading",1,0,'C',0);
	  $this->Cell($w[2],7,"B/L No.",1,0,'C',0);
	  $this->Cell($w[3],7,"Packages",1,0,'C',0);
	  $this->Cell($w[4],7,"Kgs",1,0,'C',0);
	  $this->Cell($w[5],7,"Cbm",1,0,'C',0);
	  $this->Cell($w[6],7,"Fr. Ton",1,0,'C',0);
	  $this->Ln();
		 
	  //line 1
	  $this->Cell($w[0],6,"1","LR",0,'C',0);
	  $this->Cell($w[1],6,$ResultJO[0]['port_loading'],"R",0,'L',0);
	  $this->Cell($w[2],6,$ResultJO[0]['bl_no'],"R",0,'C',0);
	  $this->Cell($w[3],6,number_format($ResultCrg[0]['c_qty'],2),"R",0,'C',0);
	  $this->Cell($w[4],6,number_format($ResultCrg[0]['c_weight'],2),"R",0,'C',0);
	  $this->Cell($w[5],6,number_format($ResultCrg[0]['c_vol'],2),"R",0,'C',0);
	  $this->Cell($w[6],6,number_format($fr_ton,2),"R",0,'C',0);
	  $this->Ln();
	  
	  //line 2
	  $this->Cell($w[0],6,"","LR",0,'C',0);
	  $this->Cell($w[1],6,"Invoice No :".$ResultJO[0]['invoice_no'],"R",0,'L',0);
	  $this->Cell($w[2],6,"","R",0,'C',0);
	  $this->Cell($w[3],6,"","R",0,'C',0);
	  $this->Cell($w[4],6,"","R",0,'C',0);
	  $this->Cell($w[5],6,"","R",0,'C',0);
	  $this->Cell($w[6],6,"","R",0,'C',0);
	  $this->Ln();
	  
	  //line 3
	  $this->Cell($w[0],4,"","LR",0,'C',0);
	  $this->Cell($w[1],4,"Scope Of Work:","R",0,'L',0);
	  $this->Cell($w[2],4,"","R",0,'C',0);
	  $this->Cell($w[3],4,"","R",0,'C',0);
	  $this->Cell($w[4],4,"","R",0,'C',0);
	  $this->Cell($w[5],4,"","R",0,'C',0);
	  $this->Cell($w[6],4,"","R",0,'C',0);
	  $this->Ln();
	  
	  //line 3
	  
	  if(!empty($ResultSrv))
	  {
	  
		  foreach($ResultSrv as $it => $value)
		  {
		  
			  $this->Cell($w[0],4,"","LR",0,'C',0);
			  $this->Cell($w[1],4,"- ".$value['services_name'],"R",0,'L',0);
			  $this->Cell($w[2],4,"","R",0,'C',0);
			  $this->Cell($w[3],4,"","R",0,'C',0);
			  $this->Cell($w[4],4,"","R",0,'C',0);
			  $this->Cell($w[5],4,"","R",0,'C',0);
			  $this->Cell($w[6],4,"","R",0,'C',0);
			  $this->Ln();
		  
		  }
		  
      }	  
	  
	 
	  $this->Cell($w[0],7,"",1,0,'C',0);
	  $this->Cell($w[1] + $w[2],7,"TOTAL",1,0,'C',0);
	  $this->Cell($w[3],7,number_format($ResultCrg[0]['c_qty'],2),1,0,'C',0);
	  $this->Cell($w[4],7,number_format($ResultCrg[0]['c_weight'],2),1,0,'C',0);
	  $this->Cell($w[5],7,number_format($ResultCrg[0]['c_vol'],2),1,0,'C',0);
	  $this->Cell($w[6],7,number_format($fr_ton,2),1,0,'C',0);
	  $this->Ln();
	  
	  
	  $this->Ln();
	  $this->Ln();
	  
            
      $this->Cell(30,5,"Accepted by",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Cell(30,5,"Site",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,$ResultJO[0]['project_name'],0,0,'L',0);
      
      $this->Ln();
      
      
      $this->Cell(30,5,"Signed by",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Cell(30,5,"Date",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,$today,0,0,'L',0);
      
      $this->Ln();
      
      
      $this->Cell(30,5,"Name",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Cell(30,5,"Rendered by",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"PT. Masaji Prayasa Cargo",0,0,'L',0);
      
      $this->Ln();
      
      
      $this->Cell(30,5,"",0,0,'L',0);
      $this->Cell(5,5,"",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Cell(30,5,"Signed by",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Ln();
      
      
      $this->Cell(30,5,"",0,0,'L',0);
      $this->Cell(5,5,"",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Cell(30,5,"Name",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(60,5,"",0,0,'L',0);
      
      $this->Ln();
      
      
      
    
     
      
      //End Text Form
      
      
         
     
	}


}


?>
